home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / axpcklst / axbutton.ctl (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-05-25  |  39.8 KB  |  935 lines

  1. VERSION 5.00
  2. Begin VB.UserControl axDataButton 
  3.    AutoRedraw      =   -1  'True
  4.    CanGetFocus     =   0   'False
  5.    ClientHeight    =   435
  6.    ClientLeft      =   0
  7.    ClientTop       =   0
  8.    ClientWidth     =   435
  9.    ScaleHeight     =   29
  10.    ScaleMode       =   3  'Pixel
  11.    ScaleWidth      =   29
  12.    ToolboxBitmap   =   "axButton.ctx":0000
  13. Attribute VB_Name = "axDataButton"
  14. Attribute VB_GlobalNameSpace = False
  15. Attribute VB_Creatable = True
  16. Attribute VB_PredeclaredId = False
  17. Attribute VB_Exposed = False
  18. Attribute VB_Ext_KEY = "PropPageWizardRun" ,"Yes"
  19. '*****************************************************************
  20. '   axButton CONTROL
  21. '   This code and control is absolutely freeware!
  22. '   You have a royalty-free right to use, modify, reproduce and distribute
  23. '   the source code and control (and/or any modified version) in any way
  24. '   you find useful, provided that you agree that the authors have no warranty,
  25. '   obligations or liability for any code distributed in this project group.
  26. '   Copyright 
  27.  1998 by Geoff Glaze
  28. '   (Some parts borrowed from Microsoft)
  29. '   If you make any improvements, the author would appreciate
  30. '   a copy of the improved source. If you include with any distribution,
  31. '   the author would appreciate notification.
  32. '   Send comments and updates to :       gglaze@transtecinc.com
  33. '   My web page (coming soon) will be :  www.cs.utexas.edu/users/gglaze
  34. '*****************************************************************
  35. Option Explicit
  36. Dim HaveCapture As Boolean
  37. Dim PaintedUp As Boolean
  38. Dim IsDown As Boolean
  39. Dim IsUp As Boolean
  40. Dim Inside As Boolean
  41. Dim ButtonVisible As Boolean
  42. 'Private mbClearURLOnly As Boolean
  43. 'Private mbClearPictureOnly As Boolean
  44. 'Private mbToolTipNotInExtender As Boolean
  45. 'Private moDrawTool As clsDrawPictures
  46. Private mbGotFocus As Boolean
  47. Private mbMouseOver As Boolean
  48. Private miCurrentState As Integer
  49. Private mWndProcNext As Long            'The address entry point for the subclassed window
  50. Private mHWndSubClassed As Long         'hWnd of the subclassed window
  51. Private mbLeftMouseDown As Boolean
  52. Private mbLeftWasDown As Boolean
  53. Private mudtButtonRect As RECT
  54. Private mudtPictureRect As RECT
  55. Private mudtPicturePoint As POINTAPI
  56. Private mbPropertiesLoaded As Boolean
  57. Private mbEnterOnce As Boolean
  58. Private mbMouseDownFired As Boolean
  59. Private mlhHalftonePal As Long
  60. Private hUpDownDitherBrush As Long
  61. Private UpDownButtonFace As Long
  62. 'Class level variables
  63. Private msToolTipBuffer As String         'Tool tip text; This string must have
  64.                                           'module or global level scope, because
  65.                                           'a pointer to it is copied into a
  66.                                           'ToolTipText structure
  67. Const cxPicture = 16
  68. Const cyPicture = 15
  69. 'Default Property Values:
  70. 'Const m_def_ToolTipText = ""
  71. Const m_def_BackStyle = 0
  72. Const m_def_BackColor = &H8000000F
  73. Const m_def_Enabled = True
  74. Const m_def_Style = 0
  75. Const m_def_Value = False
  76. Const m_def_ButtonGroup = ""
  77. Const m_def_ButtonGroupDefault = False
  78. Const m_def_ButtonGroupDefault2 = False
  79. 'Property Variables:
  80. Dim m_DownPicture As Picture
  81. Dim m_FlatPicture As Picture
  82. Dim m_DisabledPicture As Picture
  83. 'Dim m_ToolTipText As String
  84. Dim m_BackStyle As Integer
  85. Dim m_BackColor As Long
  86. Dim m_BackColorUse As Long
  87. Dim m_Picture As Picture
  88. Dim m_Enabled As Boolean
  89. Dim m_Style As Integer
  90. Dim m_Value As Boolean
  91. Dim m_ButtonGroupDefault As Boolean
  92. Dim m_ButtonGroupDefault2 As Boolean
  93. Dim m_ButtonGroup As String
  94. Public Enum PopupButtonStyle
  95.     [Toolbar Button] = 0
  96.     [Flat Button] = 1
  97.     [Separator] = 2
  98.     [Toolbar Handle] = 3
  99.     [Up-Down Button] = 4
  100.     [Standard Button] = 5
  101. End Enum
  102. Public Enum PopupButtonBackStyle
  103.     Transparent
  104.     Opaque
  105. End Enum
  106. 'Event Declarations:
  107. Event MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  108. Event Click()
  109. Private PEffect As PaintEffects
  110. Private Sub UserControl_Initialize()
  111.     Inside = False
  112.     Set PEffect = New PaintEffects
  113.     UpDownButtonFace = PEffect.AverageColors(GetSysColor(COLOR_BTNFACE), GetSysColor(COLOR_BTNHIGHLIGHT))
  114.     InitializeUpDownDither
  115. End Sub
  116. Private Sub PaintUpDownDither(x As Single, y As Single, Width As Single, Height As Single)
  117.     Dim ret As Long
  118.     Dim MyRect As RECT
  119.     'draw on the form with that brush
  120.     MyRect.Left = x
  121.     MyRect.Top = y
  122.     MyRect.Right = x + Width
  123.     MyRect.Bottom = y + Height
  124.     ret = FillRect(UserControl.hDC, MyRect, hUpDownDitherBrush)
  125. End Sub
  126. Private Sub InitializeUpDownDither()
  127.     Dim i As Long, j As Long
  128.     '---one-time setup: put this in it's own routine------
  129.     'set (invisible) picturebox properties for creating a brush
  130. '    UserControl.ScaleMode = vbPixels
  131. '    UserControl.AutoRedraw = True
  132.     'draw the dither in it
  133.     For i = 0 To UserControl.ScaleWidth - 1
  134.         For j = 0 To UserControl.ScaleHeight - 1
  135.             If (i + j) Mod 2 Then
  136.                 UserControl.PSet (i, j), vb3DHighlight
  137.             Else
  138.                 UserControl.PSet (i, j), vbButtonFace
  139.             End If
  140.         Next j
  141.     Next i
  142.     '---end of one-time setup------
  143.     'create the brush from it
  144.     hUpDownDitherBrush = CreatePatternBrush(UserControl.Image.handle)
  145. End Sub
  146. Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  147.     IsDown = True
  148.     UserControl_MouseMove Button, Shift, x, y
  149.     UserControl_Paint
  150. End Sub
  151. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  152.     Dim NeedCapture As Boolean
  153.     On Error GoTo UserCtlMouseMoveErr
  154.     Select Case m_Style
  155.         Case [Toolbar Button], [Flat Button], [Up-Down Button], [Standard Button]
  156.             ' Is the mouse inside the control's client area?
  157.             Inside = (x > 0) And (y > 0) And (x < ScaleWidth) And (y < ScaleHeight)
  158.             If Inside And m_Enabled Then
  159.                 If PaintedUp Or (Not ButtonVisible) Then
  160.                     ButtonVisible = True
  161.                     Cls
  162.                     UserControl_Paint
  163.                 End If
  164.                 If Not ((m_Style = [Up-Down Button]) And m_Value) Then
  165.                     DrawShadowBox 0, 0, ScaleWidth, ScaleHeight, IsDown, ((m_Style = [Flat Button]) Or (m_Style = [Standard Button]))
  166.                 Else
  167.                     DrawShadowBox 0, 0, ScaleWidth, ScaleHeight, True, ((m_Style = [Flat Button]) Or (m_Style = [Standard Button]))
  168.                 End If
  169.             Else
  170.                 If IsDown And m_Enabled Then
  171.                     If Not (PaintedUp And ButtonVisible) Then
  172.                         ButtonVisible = True
  173.                         Cls
  174.                         UserControl_Paint
  175.                     End If
  176.                     DrawShadowBox 0, 0, ScaleWidth, ScaleHeight, False, ((m_Style = [Flat Button]) Or (m_Style = [Standard Button]))
  177.                 Else
  178.                     If ButtonVisible Then
  179.                         ButtonVisible = False
  180.                         Cls
  181.                         UserControl_Paint
  182.                     End If
  183.                     If Not (((m_Style = [Up-Down Button]) And m_Value) Or (m_Style = [Standard Button])) Then
  184.                         Line (0, 0)-(ScaleWidth, ScaleHeight), m_BackColorUse, B
  185.                         Line (1, 1)-(ScaleWidth - 1, ScaleHeight - 1), m_BackColorUse, B
  186.                     End If
  187.                 End If
  188.             End If
  189.             
  190.             NeedCapture = (IsDown Or (Inside And (Not IsUp))) And m_Enabled
  191.             If IsUp Then IsUp = False
  192.             
  193.             ' Set or release mouse capture if necessary
  194.             If NeedCapture And (HaveCapture = False) Then
  195.                 SetCapture hwnd
  196.                 HaveCapture = True
  197.             ElseIf (NeedCapture = False) And HaveCapture Then
  198.                 ReleaseCapture
  199.                 HaveCapture = False
  200.             End If
  201.     End Select
  202.     RaiseEvent MouseMove(Button, Shift, x, y)
  203.     Exit Sub
  204. UserCtlMouseMoveErr:
  205.     Exit Sub
  206. End Sub
  207. Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  208.     If IsDown And m_Enabled And Inside Then
  209.         If m_Style = [Up-Down Button] Then
  210.             m_Value = Not m_Value
  211.             CheckButtonGroup
  212.         End If
  213.         RaiseEvent Click
  214.     End If
  215.     IsDown = False
  216.     IsUp = True
  217.     On Error Resume Next
  218.     UserControl_MouseMove Button, Shift, -1, -1 'X, Y
  219.     UserControl_Paint
  220. End Sub
  221. Private Sub UserControl_Paint()
  222.     On Error Resume Next
  223.     Select Case m_Style
  224.         Case [Toolbar Button], [Flat Button], [Up-Down Button], [Standard Button]
  225.             PaintedUp = Not (IsDown And Inside)
  226.             If ButtonVisible Then
  227.                 If (m_Style = [Flat Button]) Or (m_Style = [Standard Button]) Then
  228.                     If PaintedUp Then
  229.                         Line (1, 1)-(ScaleWidth - 2, ScaleHeight - 2), vbButtonFace, BF
  230.                     Else
  231.                         Line (2, 2)-(ScaleWidth - 2, ScaleHeight - 2), vbButtonFace, BF
  232.                     End If
  233.                 Else
  234.                     Line (1, 1)-(ScaleWidth - 2, ScaleHeight - 2), vbButtonFace, BF
  235.                 End If
  236.             Else
  237.                 If (m_Style = [Up-Down Button]) Then
  238.                     If m_Value Then
  239.                         If Inside Then
  240.                             Line (1, 1)-(ScaleWidth - 2, ScaleHeight - 2), vbButtonFace, BF
  241.                         Else
  242.                             'use this to dither:
  243.                             PaintUpDownDither 1, 1, ScaleWidth - 2, ScaleHeight - 2
  244.                             'use this to average:
  245.                             'Line (1, 1)-(ScaleWidth - 1, ScaleHeight - 1), UpDownButtonFace, BF
  246.                         End If
  247.                         DrawShadowBox 0, 0, ScaleWidth, ScaleHeight, True, False
  248.                     Else
  249.                         Line (0, 0)-(ScaleWidth, ScaleHeight), m_BackColorUse, BF
  250.                     End If
  251.                 ElseIf (m_Style = [Standard Button]) Then
  252.                     If PaintedUp Then
  253.                         Line (1, 1)-(ScaleWidth - 2, ScaleHeight - 2), vbButtonFace, BF
  254.                     Else
  255.                         Line (2, 2)-(ScaleWidth - 1, ScaleHeight - 1), vbButtonFace, BF
  256.                     End If
  257.                     DrawShadowBox 0, 0, ScaleWidth, ScaleHeight, False, True
  258.                 Else
  259.                     Line (0, 0)-(ScaleWidth, ScaleHeight), m_BackColorUse, BF
  260.                 End If
  261.             End If
  262.             If IsAPicture(m_Picture) Then
  263.                 Dim xPixels As Long, yPixels As Long
  264.                 If m_Enabled Then
  265.                     Dim picUse As StdPicture
  266.                     If (IsDown Or ((m_Style = [Up-Down Button]) And m_Value)) And IsAPicture(m_DownPicture) Then
  267.                         Set picUse = m_DownPicture
  268.                     ElseIf Inside Or Not IsAPicture(m_FlatPicture) Then
  269.                         Set picUse = m_Picture
  270.                     Else
  271.                         Set picUse = m_FlatPicture
  272.                     End If
  273.                     xPixels = CLng(UserControl.ScaleX(picUse.Width, vbHimetric, vbPixels))
  274.                     yPixels = CLng(UserControl.ScaleY(picUse.Height, vbHimetric, vbPixels))
  275.                     PEffect.PaintTransCornerStdPic UserControl.hDC, (ScaleWidth - xPixels) / 2 + IIf(Not PaintedUp, 1, 0), (ScaleHeight - yPixels) / 2 + IIf(Not PaintedUp, 1, 0), xPixels, yPixels, picUse, 0, 0
  276. '                    PEffect.PaintGreyScaleCornerStdPic UserControl.hDC, (ScaleWidth - xPixels) / 2 + IIf(Not PaintedUp, 1, 0), (ScaleHeight - yPixels) / 2 + IIf(Not PaintedUp, 1, 0), xPixels, yPixels, picUse, 0, 0
  277.                 Else
  278.                     PaintedUp = True
  279.                     If IsAPicture(m_DisabledPicture) Then
  280.                         xPixels = CLng(UserControl.ScaleX(m_DisabledPicture.Width, vbHimetric, vbPixels))
  281.                         yPixels = CLng(UserControl.ScaleY(m_DisabledPicture.Height, vbHimetric, vbPixels))
  282.                         PEffect.PaintTransCornerStdPic UserControl.hDC, (ScaleWidth - xPixels) / 2 + IIf(Not PaintedUp, 1, 0), (ScaleHeight - yPixels) / 2 + IIf(Not PaintedUp, 1, 0), xPixels, yPixels, m_DisabledPicture, 0, 0
  283.                     Else
  284.                         xPixels = CLng(UserControl.ScaleX(m_Picture.Width, vbHimetric, vbPixels))
  285.                         yPixels = CLng(UserControl.ScaleY(m_Picture.Height, vbHimetric, vbPixels))
  286.                         PEffect.PaintDisabledCornerStdPic UserControl.hDC, (ScaleWidth - xPixels) / 2 + IIf(Not PaintedUp, 1, 0), (ScaleHeight - yPixels) / 2 + IIf(Not PaintedUp, 1, 0), xPixels, yPixels, m_Picture, 0, 0
  287.                     End If
  288.                 End If
  289.             End If
  290.         Case [Separator]
  291.             Line (0, 0)-(ScaleWidth, ScaleHeight), m_BackColorUse, BF
  292.             DrawVLine ScaleWidth \ 2 - 1, 0, 2, ScaleHeight
  293.         Case [Toolbar Handle]
  294.             Line (0, 0)-(ScaleWidth, ScaleHeight), m_BackColorUse, BF
  295.             DrawRaisedVLine ScaleWidth \ 2 - 4, 0, 3, ScaleHeight
  296.             DrawRaisedVLine ScaleWidth \ 2, 0, 3, ScaleHeight
  297.     End Select
  298. End Sub
  299. Private Function IsAPicture(pic As StdPicture) As Boolean
  300.     If (pic Is Nothing) Then
  301.         IsAPicture = False
  302.     Else
  303.         IsAPicture = (pic <> 0)
  304.     End If
  305. End Function
  306. Private Sub DrawShadowBox(ByVal x As Single, ByVal y As Single, ByVal cx As Single, ByVal cy As Single, ByVal Pressed As Boolean, ByVal DKShadow As Boolean)
  307.     If DKShadow Then
  308.         If Pressed Then
  309.             Line (x, y)-(x + cx - 1, y), vb3DDKShadow
  310.             Line (x, y)-(x, y + cy - 1), vb3DDKShadow
  311.             Line (x + 1, y + 1)-(x + cx - 2, y + 1), vbButtonShadow
  312.             Line (x + 1, y + 1)-(x + 1, y + cy - 2), vbButtonShadow
  313.             Line (x + cx - 1, y)-(x + cx - 1, y + cy), vb3DHighlight
  314.             Line (x, y + cy - 1)-(x + cx, y + cy - 1), vb3DHighlight
  315.         Else
  316.             Line (x, y)-(x + cx - 1, y), vb3DHighlight
  317.             Line (x, y)-(x, y + cy - 1), vb3DHighlight
  318.             Line (x + cx - 2, y + 1)-(x + cx - 2, y + cy - 1), vbButtonShadow
  319.             Line (x + 1, y + cy - 2)-(x + cx - 1, y + cy - 2), vbButtonShadow
  320.             Line (x + cx - 1, y)-(x + cx - 1, y + cy), vb3DDKShadow
  321.             Line (x, y + cy - 1)-(x + cx, y + cy - 1), vb3DDKShadow
  322.         End If
  323.     Else
  324.         Dim Color1 As Long
  325.         Dim Color2 As Long
  326.         If Pressed Then
  327.             Color1 = vbButtonShadow
  328.             Color2 = vb3DHighlight
  329.         Else
  330.             Color1 = vb3DHighlight
  331.             Color2 = vbButtonShadow
  332.         End If
  333.         Line (x, y)-(x + cx - 1, y), Color1
  334.         Line (x, y)-(x, y + cy - 1), Color1
  335.         Line (x + cx - 1, y)-(x + cx - 1, y + cy), Color2
  336.         Line (x, y + cy - 1)-(x + cx, y + cy - 1), Color2
  337.     End If
  338. End Sub
  339. Private Sub DrawVLine(ByVal x As Single, ByVal y As Single, ByVal cx As Single, ByVal cy As Single)
  340.     Line (x + 1, y)-(x + 1, y + cy), vb3DHighlight
  341.     Line (x, y)-(x, y + cy), vbButtonShadow
  342. End Sub
  343. Private Sub DrawRaisedVLine(ByVal x As Single, ByVal y As Single, ByVal cx As Single, ByVal cy As Single)
  344.     Line (x, y)-(x, y + cy), vb3DHighlight
  345.     Line (x + 1, y)-(x + 1, y + cy), vb3DHighlight
  346.     Line (x + 2, y)-(x + 2, y + cy), vb3DHighlight
  347.     Line (x, y + 1)-(x, y + cy), vbButtonShadow
  348.     Line (x + 1, y + 1)-(x + 1, y + cy), vbButtonShadow
  349.     Line (x + 2, y + 1)-(x + 2, y + cy), vbButtonShadow
  350.     Line (x, y)-(x, y + cy - 1), vb3DHighlight
  351.     Line (x + 1, y + 1)-(x + 1, y + cy - 1), vbButtonFace
  352. End Sub
  353. 'Load property values from storage
  354. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  355.     On Error Resume Next
  356.     Set m_Picture = PropBag.ReadProperty("Picture", Nothing)
  357.     m_Enabled = PropBag.ReadProperty("Enabled", m_def_Enabled)
  358.     m_Style = PropBag.ReadProperty("Style", m_def_Style)
  359.     m_Value = PropBag.ReadProperty("Value", m_def_Value)
  360.     m_ButtonGroup = PropBag.ReadProperty("ButtonGroup", m_def_ButtonGroup)
  361.     m_ButtonGroupDefault = PropBag.ReadProperty("ButtonGroupDefault", m_def_ButtonGroupDefault)
  362.     m_ButtonGroupDefault2 = PropBag.ReadProperty("ButtonGroupDefault2", m_def_ButtonGroupDefault2)
  363.     m_BackStyle = PropBag.ReadProperty("BackStyle", m_def_BackStyle)
  364.     m_BackColor = PropBag.ReadProperty("BackColor", UserControl.Extender.Container.BackColor)
  365. '    m_BackColor = PropBag.ReadProperty("BackColor", m_def_BackColor)
  366.     SetBackColor
  367. '    m_ToolTipText = PropBag.ReadProperty("ToolTipText", m_def_ToolTipText)
  368. '    ToolTipText = m_ToolTipText
  369.     Set m_DownPicture = PropBag.ReadProperty("DownPicture", Nothing)
  370.     Set m_FlatPicture = PropBag.ReadProperty("FlatPicture", Nothing)
  371.     Set m_DisabledPicture = PropBag.ReadProperty("DisabledPicture", Nothing)
  372.     InstanciateToolTipsWindow
  373. End Sub
  374. Private Sub UserControl_Resize()
  375.     UserControl_Paint
  376. End Sub
  377. Private Sub UserControl_Show()
  378.     UserControl_Paint
  379. End Sub
  380. Private Sub UserControl_Terminate()
  381.     Set PEffect = Nothing
  382.     glToolsCount = glToolsCount - 1
  383.     UnSubClass
  384.     If gbToolTipsInstanciated And glToolsCount = 0 Then
  385.         DestroyWindow gHWndToolTip
  386.     End If
  387.     'clean up
  388.     Call DeleteObject(hUpDownDitherBrush)
  389. End Sub
  390. 'Write property values to storage
  391. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  392.     Call PropBag.WriteProperty("Picture", m_Picture, Nothing)
  393.     Call PropBag.WriteProperty("Enabled", m_Enabled, m_def_Enabled)
  394.     Call PropBag.WriteProperty("Style", m_Style, m_def_Style)
  395.     Call PropBag.WriteProperty("Value", m_Value, m_def_Value)
  396.     Call PropBag.WriteProperty("ButtonGroup", m_ButtonGroup, m_def_ButtonGroup)
  397.     Call PropBag.WriteProperty("ButtonGroupDefault", m_ButtonGroupDefault, m_def_ButtonGroupDefault)
  398.     Call PropBag.WriteProperty("ButtonGroupDefault2", m_ButtonGroupDefault2, m_def_ButtonGroupDefault2)
  399.     Call PropBag.WriteProperty("BackStyle", m_BackStyle, m_def_BackStyle)
  400.     Call PropBag.WriteProperty("BackColor", m_BackColor, UserControl.Extender.Container.BackColor)
  401. '    Call PropBag.WriteProperty("BackColor", m_BackColor, m_def_BackColor)
  402. '    Call PropBag.WriteProperty("ToolTipText", m_ToolTipText, m_def_ToolTipText)
  403.     Call PropBag.WriteProperty("DownPicture", m_DownPicture, Nothing)
  404.     Call PropBag.WriteProperty("FlatPicture", m_FlatPicture, Nothing)
  405.     Call PropBag.WriteProperty("DisabledPicture", m_DisabledPicture, Nothing)
  406. End Sub
  407. Public Property Get Picture() As Picture
  408.     Set Picture = m_Picture
  409. End Property
  410. Public Property Set Picture(ByVal New_Picture As Picture)
  411.     Set m_Picture = New_Picture
  412.     If m_Enabled Then
  413.         Cls
  414.         UserControl_Paint
  415.     End If
  416.     PropertyChanged "Picture"
  417. End Property
  418. Public Property Get DownPicture() As Picture
  419.     Set DownPicture = m_DownPicture
  420. End Property
  421. Public Property Set DownPicture(ByVal New_DownPicture As Picture)
  422.     Set m_DownPicture = New_DownPicture
  423.     If m_Enabled Then
  424.         Cls
  425.         UserControl_Paint
  426.     End If
  427.     PropertyChanged "DownPicture"
  428. End Property
  429. Public Property Get FlatPicture() As Picture
  430.     Set FlatPicture = m_FlatPicture
  431. End Property
  432. Public Property Set FlatPicture(ByVal New_FlatPicture As Picture)
  433.     Set m_FlatPicture = New_FlatPicture
  434.     If m_Enabled Then
  435.         Cls
  436.         UserControl_Paint
  437.     End If
  438.     PropertyChanged "FlatPicture"
  439. End Property
  440. Public Property Get DisabledPicture() As Picture
  441.     Set DisabledPicture = m_DisabledPicture
  442. End Property
  443. Public Property Set DisabledPicture(ByVal New_DisabledPicture As Picture)
  444.     Set m_DisabledPicture = New_DisabledPicture
  445.     If Not m_Enabled Then
  446.         Cls
  447.         UserControl_Paint
  448.     End If
  449.     PropertyChanged "DisabledPicture"
  450. End Property
  451. 'Initialize Properties for User Control
  452. Private Sub UserControl_InitProperties()
  453.     Set m_Picture = LoadPicture("")
  454.     Set m_FlatPicture = LoadPicture("")
  455.     Set m_DownPicture = LoadPicture("")
  456.     Set m_DisabledPicture = LoadPicture("")
  457.     m_Value = m_def_Value
  458.     m_ButtonGroup = m_def_ButtonGroup
  459.     m_ButtonGroupDefault = m_def_ButtonGroupDefault
  460.     m_ButtonGroupDefault2 = m_def_ButtonGroupDefault2
  461.     m_Enabled = m_def_Enabled
  462.     m_Style = m_def_Style
  463.     m_BackStyle = m_def_BackStyle
  464.     m_BackColor = UserControl.Extender.Container.BackColor
  465. '    m_BackColor = m_def_BackColor
  466.     SetBackColor
  467. '    m_ToolTipText = m_def_ToolTipText
  468. '    UserControl.Extender.ToolTipText = m_ToolTipText
  469.     UserControl_Resize
  470. End Sub
  471. Public Property Get ButtonGroup() As String
  472.     ButtonGroup = m_ButtonGroup
  473. End Property
  474. Public Property Let ButtonGroup(ByVal New_ButtonGroup As String)
  475.     If Not (m_ButtonGroup = New_ButtonGroup) Then
  476.         m_ButtonGroup = New_ButtonGroup
  477.         If m_Style = [Up-Down Button] Then
  478.             CheckButtonGroup
  479.             Cls
  480.             UserControl_Paint
  481.         End If
  482.     End If
  483.     PropertyChanged "ButtonGroup"
  484. End Property
  485. Public Property Get ButtonGroupDefault() As Boolean
  486.     ButtonGroupDefault = m_ButtonGroupDefault
  487. End Property
  488. Public Property Let ButtonGroupDefault(ByVal New_ButtonGroupDefault As Boolean)
  489.     'The following line of code ensures that the integer
  490.     'value of the boolean parameter is either
  491.     '0 or -1.  It is known that Access 97 will
  492.     'set the boolean's value to 255 for true.
  493.     'In this case a P-Code compiled VB5 built
  494.     'OCX will return True for the expression
  495.     '(Not [boolean variable that ='s 255]).  This
  496.     'line ensures the reliability of boolean operations
  497.     If CBool(New_ButtonGroupDefault) Then New_ButtonGroupDefault = True Else New_ButtonGroupDefault = False
  498.     If Not (m_ButtonGroupDefault = New_ButtonGroupDefault) Then
  499.         m_ButtonGroupDefault = New_ButtonGroupDefault
  500.         If m_Style = [Up-Down Button] Then
  501.             CheckButtonGroupDefault
  502.             CheckButtonGroup
  503.             Cls
  504.             UserControl_Paint
  505.         End If
  506.     End If
  507.     PropertyChanged "ButtonGroupDefault"
  508. End Property
  509. Private Sub CheckButtonGroupDefault()
  510.     If (Len(m_ButtonGroup) > 0) Then
  511.         If m_ButtonGroupDefault Then     ' make all others in group not default
  512.             Dim ctl As Control
  513.             Dim i As Long
  514.             For i = 0 To UserControl.ParentControls.Count - 1
  515.                 If TypeOf UserControl.ParentControls(i) Is Control Then
  516.                     Set ctl = UserControl.ParentControls(i)
  517.                     If TypeOf ctl Is axDataButton Then
  518.                         If ctl.ButtonGroup = m_ButtonGroup Then
  519.                             If Not ((ctl Is UserControl.Extender) Or (ctl Is UserControl)) Then
  520.                                 ctl.ButtonGroupDefault = False
  521.                             End If
  522.                         End If
  523.                     End If
  524.                 End If
  525.             Next
  526.         End If
  527.     End If
  528. End Sub
  529. Public Property Get ButtonGroupDefault2() As Boolean
  530.     ButtonGroupDefault2 = m_ButtonGroupDefault2
  531. End Property
  532. Public Property Let ButtonGroupDefault2(ByVal New_ButtonGroupDefault2 As Boolean)
  533.     'The following line of code ensures that the integer
  534.     'value of the boolean parameter is either
  535.     '0 or -1.  It is known that Access 97 will
  536.     'set the boolean's value to 255 for true.
  537.     'In this case a P-Code compiled VB5 built
  538.     'OCX will return True for the expression
  539.     '(Not [boolean variable that ='s 255]).  This
  540.     'line ensures the reliability of boolean operations
  541.     If CBool(New_ButtonGroupDefault2) Then New_ButtonGroupDefault2 = True Else New_ButtonGroupDefault2 = False
  542.     If Not (m_ButtonGroupDefault2 = New_ButtonGroupDefault2) Then
  543.         m_ButtonGroupDefault2 = New_ButtonGroupDefault2
  544.         If m_Style = [Up-Down Button] Then
  545.             CheckButtonGroupDefault2
  546.             CheckButtonGroup
  547.             Cls
  548.             UserControl_Paint
  549.         End If
  550.     End If
  551.     PropertyChanged "ButtonGroupDefault2"
  552. End Property
  553. Private Sub CheckButtonGroupDefault2()
  554.     If (Len(m_ButtonGroup) > 0) Then
  555.         If m_ButtonGroupDefault2 Then     ' make all others in group not default
  556.             Dim ctl As Control
  557.             Dim i As Long
  558.             For i = 0 To UserControl.ParentControls.Count - 1
  559.                 If TypeOf UserControl.ParentControls(i) Is Control Then
  560.                     Set ctl = UserControl.ParentControls(i)
  561.                     If TypeOf ctl Is axDataButton Then
  562.                         If ctl.ButtonGroup = m_ButtonGroup Then
  563.                             If Not ((ctl Is UserControl.Extender) Or (ctl Is UserControl)) Then
  564.                                 ctl.ButtonGroupDefault2 = False
  565.                             End If
  566.                         End If
  567.                     End If
  568.                 End If
  569.             Next
  570.         End If
  571.     End If
  572. End Sub
  573. Private Sub CheckButtonGroup()
  574.     If (Len(m_ButtonGroup) > 0) Then
  575.         Dim ctl As Control
  576.         Dim i As Long
  577.         If m_Value Then     ' clear all others in group
  578.             For i = 0 To UserControl.ParentControls.Count - 1
  579.                 If TypeOf UserControl.ParentControls(i) Is Control Then
  580.                     Set ctl = UserControl.ParentControls(i)
  581.                     If TypeOf ctl Is axDataButton Then
  582.                         If ctl.ButtonGroup = m_ButtonGroup Then
  583.                             If Not ((ctl Is UserControl.Extender) Or (ctl Is UserControl)) Then
  584.                                 ctl.Value = False
  585.                             End If
  586.                         End If
  587.                     End If
  588.                 End If
  589.             Next
  590.         Else                 ' set group default if necessary
  591.             Dim GroupValueSet As Boolean
  592.             Dim ctlDefault As axDataButton
  593.             Dim ctlDefault2 As axDataButton
  594.             Set ctlDefault = Nothing
  595.             Set ctlDefault2 = Nothing
  596.             GroupValueSet = False
  597.             For i = 0 To UserControl.ParentControls.Count - 1
  598.                 If TypeOf UserControl.ParentControls(i) Is Control Then
  599.                     Set ctl = UserControl.ParentControls(i)
  600.                     If TypeOf ctl Is axDataButton Then
  601.                         If ctl.ButtonGroup = m_ButtonGroup Then
  602. '                            If Not ((ctl Is UserControl.Extender) Or (ctl Is UserControl)) Then
  603.                                 If ctl.Value Then
  604.                                     GroupValueSet = True
  605.                                     Exit For
  606.                                 ElseIf ctl.ButtonGroupDefault Then
  607.                                     Set ctlDefault = ctl
  608.                                 ElseIf ctl.ButtonGroupDefault2 Then
  609.                                     Set ctlDefault2 = ctl
  610.                                 End If
  611. '                            End If
  612.                         End If
  613.                     End If
  614.                 End If
  615.             Next
  616.             If Not (GroupValueSet Or (ctlDefault Is Nothing)) Then
  617.                 If (Not m_ButtonGroupDefault) Or (ctlDefault2 Is Nothing) Then
  618.                     ctlDefault.Value = True
  619.                 Else
  620.                     ctlDefault2.Value = True
  621.                 End If
  622.             End If
  623.         End If
  624.     End If
  625. End Sub
  626. Public Property Get Value() As Boolean
  627.     Value = m_Value
  628. End Property
  629. Public Property Let Value(ByVal New_Value As Boolean)
  630.     'The following line of code ensures that the integer
  631.     'value of the boolean parameter is either
  632.     '0 or -1.  It is known that Access 97 will
  633.     'set the boolean's value to 255 for true.
  634.     'In this case a P-Code compiled VB5 built
  635.     'OCX will return True for the expression
  636.     '(Not [boolean variable that ='s 255]).  This
  637.     'line ensures the reliability of boolean operations
  638.     If CBool(New_Value) Then New_Value = True Else New_Value = False
  639.     If Not (m_Value = New_Value) Then
  640.         m_Value = New_Value
  641.         If m_Style = [Up-Down Button] Then
  642.             CheckButtonGroup
  643.             Cls
  644.             UserControl_Paint
  645.         End If
  646.     End If
  647.     PropertyChanged "Value"
  648. End Property
  649. Public Property Get Enabled() As Boolean
  650.     Enabled = m_Enabled
  651. End Property
  652. Public Property Let Enabled(ByVal New_Enabled As Boolean)
  653.     'The following line of code ensures that the integer
  654.     'value of the boolean parameter is either
  655.     '0 or -1.  It is known that Access 97 will
  656.     'set the boolean's value to 255 for true.
  657.     'In this case a P-Code compiled VB5 built
  658.     'OCX will return True for the expression
  659.     '(Not [boolean variable that ='s 255]).  This
  660.     'line ensures the reliability of boolean operations
  661.     If CBool(New_Enabled) Then New_Enabled = True Else New_Enabled = False
  662.     If Not (m_Enabled = New_Enabled) Then
  663.         m_Enabled = New_Enabled
  664.         Inside = False
  665.         Cls
  666.         UserControl_Paint
  667.     End If
  668.     PropertyChanged "Enabled"
  669. End Property
  670. Public Property Get Style() As PopupButtonStyle
  671.     Style = m_Style
  672. End Property
  673. Public Property Let Style(ByVal New_Style As PopupButtonStyle)
  674.     If Not (m_Style = New_Style) Then
  675.         m_Style = New_Style
  676.         Cls
  677.         UserControl_Paint
  678.     End If
  679.     PropertyChanged "Style"
  680. End Property
  681. Public Property Get BackStyle() As PopupButtonBackStyle
  682.     BackStyle = m_BackStyle
  683. End Property
  684. Public Property Let BackStyle(ByVal New_BackStyle As PopupButtonBackStyle)
  685.     If Not (m_BackStyle = New_BackStyle) Then
  686.         m_BackStyle = New_BackStyle
  687.         SetBackColor
  688.         Cls
  689.         UserControl_Paint
  690.     End If
  691.     PropertyChanged "BackStyle"
  692. End Property
  693. Public Property Get BackColor() As OLE_COLOR
  694.     BackColor = m_BackColor
  695. End Property
  696. Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
  697.     If Not (m_BackColor = New_BackColor) Then
  698.         m_BackColor = New_BackColor
  699.         SetBackColor
  700.         Cls
  701.         UserControl_Paint
  702.     End If
  703.     PropertyChanged "BackColor"
  704. End Property
  705. Private Sub SetBackColor()
  706.     If (m_BackStyle = Opaque) Then
  707.         m_BackColorUse = m_BackColor
  708.     Else
  709.         m_BackColorUse = UserControl.Extender.Container.BackColor
  710.     End If
  711. End Sub
  712. 'Public Property Get ToolTipText() As String
  713. '    ToolTipText = m_ToolTipText
  714. 'End Property
  715. 'Public Property Let ToolTipText(ByVal New_ToolTipText As String)
  716. '    MsgBox "let : " & New_ToolTipText
  717. '    m_ToolTipText = New_ToolTipText
  718. ''    UserControl.Extender.ToolTipText = m_ToolTipText
  719. '    PropertyChanged "ToolTipText"
  720. 'End Property
  721. '*************************
  722. 'Private Procedures
  723. '*************************
  724. 'Private Sub MakeClick()
  725. '    '-------------------------------------------------------------------------
  726. '    'Purpose:   Raise a Click event to container, play sound
  727. '    '-------------------------------------------------------------------------
  728. '    '-----------------------------------------
  729. '    '- Added for sound support
  730. '    '-----------------------------------------
  731. '    If m_bPlaySounds Then PlaySound EVENT_MENU_COMMAND, 0, SND_SYNC
  732. '    '-----------------------------------------
  733. '    RaiseEvent Click
  734. 'End Sub
  735. 'Private Sub MouseOver()
  736. '    '-------------------------------------------------------------------------
  737. '    'Purpose:   Call whenever the mouse is over the button and
  738. '    '           button needs raised appearance and capture set
  739. '    '-------------------------------------------------------------------------
  740. '    If miCurrentState <> giRAISED Then DrawButtonState giRAISED
  741. '    If Not mbMouseOver Then
  742. '        Capture True
  743. '        mbMouseOver = True
  744. '        '-----------------------------------------
  745. '        '- Added for sound support
  746. '        '-----------------------------------------
  747. '        If Not mbEnterOnce Then
  748. '            RaiseEvent PopUp
  749. '            If m_bPlaySounds Then PlaySound EVENT_MENU_POPUP, 0, SND_SYNC
  750. '            mbEnterOnce = True
  751. '        End If
  752. '        '-----------------------------------------
  753. '    End If
  754. 'End Sub
  755. 'Private Sub Flatten()
  756. '    '-------------------------------------------------------------------------
  757. '    'Purpose:   Call whenever the mouse is off the control
  758. '    '           and capture needs released and button needs
  759. '    '           flattened appearance
  760. '    '-------------------------------------------------------------------------
  761. '    If mbMouseOver Then Capture False
  762. '    mbMouseOver = False
  763. '    If (Not mbGotFocus) And miCurrentState <> giFLATTENED Then DrawButtonState giFLATTENED
  764. '    '-----------------------------------------
  765. '    '- Added for sound support
  766. '    '-----------------------------------------
  767. '    '   PlaySound EVENT_MENU_POPUP, 0, SND_SYNC
  768. '    mbEnterOnce = False
  769. '    '-----------------------------------------
  770. 'End Sub
  771. 'Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty)
  772. '    On Error GoTo ErrorHandler
  773. '    If (AsyncProp.PropertyName = msPICTURE_NAME) Then ' Picture download is complete
  774. '        mbClearPictureOnly = True
  775. '        Set Picture = AsyncProp.Value           ' Store picture data to property...
  776. '    End If
  777. 'ErrorHandler:
  778. '    mbClearPictureOnly = False
  779. 'End Sub
  780. Private Sub AddTool(hwnd As Long)
  781.     '-------------------------------------------------------------------------
  782.     'Purpose:   Add a tool to the ToolTips object
  783.     'In:        [hWnd]
  784.     '               hWnd of Tool being added
  785.     '-------------------------------------------------------------------------
  786.                    
  787.     Dim ti As TOOLINFO
  788.     With ti
  789.         .cbSize = Len(ti)
  790.         .uId = hwnd
  791.         .hwnd = hwnd
  792.         .hinst = App.hInstance
  793.         .uFlags = TTF_IDISHWND
  794.         .lpszText = LPSTR_TEXTCALLBACK
  795.     End With
  796.     SendMessage gHWndToolTip, TTM_ADDTOOL, 0, ti
  797.     SendMessage gHWndToolTip, TTM_ACTIVATE, 1, ByVal hwnd
  798.     Exit Sub
  799. End Sub
  800. Private Sub InstanciateToolTipsWindow()
  801.     '-------------------------------------------------------------------------
  802.     'Purpose:   Instanciate needed collections.
  803.     '           Create ToolTips Class window
  804.     '-------------------------------------------------------------------------
  805.     If Not (TypeOf UserControl.Extender.Parent Is axPicker) Then Exit Sub
  806.     glToolsCount = glToolsCount + 1
  807.     If UserControl.Extender.Parent.Ambient.UserMode Then
  808.         If Not gbToolTipsInstanciated Then
  809.             gbToolTipsInstanciated = True
  810.             InitCommonControls
  811.             gHWndToolTip = CreateWindowEX(WS_EX_TOPMOST, TOOLTIPS_CLASS, vbNullString, 0, _
  812.                       CW_USEDEFAULT, CW_USEDEFAULT, _
  813.                       CW_USEDEFAULT, CW_USEDEFAULT, _
  814.                       0, 0, _
  815.                       App.hInstance, _
  816.                       ByVal 0)
  817.             SendMessage gHWndToolTip, TTM_ACTIVATE, 1, ByVal 0
  818.             
  819.             #If DEBUGSUBCLASS Then
  820.                 If goWindowProcHookCreator Is Nothing Then Set goWindowProcHookCreator = CreateObject("DbgWindowProc.WindowProcHookCreator")
  821.             #End If
  822.         End If
  823.         'Sub class this code module to receive
  824.         'window messages for the Usercontrol
  825.         SubClass UserControl.hwnd
  826.         'Add Register Usercontrol with ToolTip window
  827.         AddTool UserControl.hwnd
  828.     End If
  829. End Sub
  830. Private Sub SubClass(hwnd)
  831.     '-------------------------------------------------------------------------
  832.     'Purpose:   Subclass control so that the ToolTip Need text message can be
  833.     '           handled.  Store handle of class as UserData of control window
  834.     '-------------------------------------------------------------------------
  835.     Dim lresult As Long
  836.     UnSubClass
  837.     #If DEBUGSUBCLASS Then
  838.         'If in debug, SubClass window using address of WindowProcHook
  839.         'Let WindowProcHook CallWindowProc at address of my function
  840.         'if in run mode but call the previous address if in break mode
  841.         'this prevents crashes in break mode
  842.         Set moProcHook = goWindowProcHookCreator.CreateWindowProcHook
  843.         With moProcHook
  844.             .SetMainProc AddressOf SubWndProc
  845.             mWndProcNext = SetWindowLong(hwnd, GWL_WNDPROC, CLng(.ProcAddress))
  846.             .SetDebugProc mWndProcNext
  847.         End With
  848.     #Else
  849.         mWndProcNext = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubWndProc)
  850.     #End If
  851.     If mWndProcNext Then
  852.         mHWndSubClassed = hwnd
  853.         lresult = SetWindowLong(hwnd, GWL_USERDATA, ObjPtr(Me))
  854.     End If
  855. End Sub
  856. Private Sub UnSubClass()
  857.     '-------------------------------------------------------------------------
  858.     'Purpose:   Unsubclass control
  859.     '-------------------------------------------------------------------------
  860.     If mWndProcNext Then
  861.         SetWindowLong mHWndSubClassed, GWL_WNDPROC, mWndProcNext
  862.         mWndProcNext = 0
  863.         
  864.         #If DEBUGSUBCLASS Then
  865.             Set moProcHook = Nothing
  866.         #End If
  867.         
  868.     End If
  869. End Sub
  870. '*************************
  871. 'Friend Methods
  872. '*************************
  873. Friend Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  874.     '-------------------------------------------------------------------------
  875.     'Purpose:   Handles window messages specific to subclassed window associated
  876.     '           with this object.  Is called by SubWndProc in standard module.
  877.     '           Relays all mouse messages to ToolTip window, and returns a value
  878.     '           for ToolTip NeedText message.
  879.     '-------------------------------------------------------------------------
  880.     Dim msgStruct As MSG
  881.     Dim hdr As NMHDR
  882.     Dim ttt As ToolTipText
  883.     On Error GoTo WindowProc_Error
  884.     Select Case uMsg
  885.         Case WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP
  886.             With msgStruct
  887.                 .lParam = lParam
  888.                 .wParam = wParam
  889.                 .message = uMsg
  890.                 .hwnd = hwnd
  891.             End With
  892.             If m_Enabled Then
  893.                 SendMessage gHWndToolTip, TTM_RELAYEVENT, 0, msgStruct
  894.             End If
  895.         Case WM_NOTIFY
  896.             CopyMemory hdr, ByVal lParam, Len(hdr)
  897.             If hdr.code = TTN_NEEDTEXT And hdr.hwndFrom = gHWndToolTip Then
  898.                 'Get the tooltip text from the UserControl class object
  899.                 'If the host for this control provides a ToolTipText property
  900.                 'on the extender object (as in VB5).  The ToolTipText property
  901.                 'declares will not be hit.  Therefore, the user's ToolTipText
  902.                 'may be found either in the Extender.ToolTipText property or
  903.                 'in my own member variable m_sToolTipText
  904.                 'Error may occur if ToolTipText property is not available
  905.                 'On Error Resume Next
  906. '                If mbToolTipNotInExtender Then
  907. '                    msToolTipBuffer = StrConv(m_sToolTipText, vbFromUnicode)
  908. '                Else
  909. '                    msToolTipBuffer = StrConv(UserControl.Extender.ToolTipText, vbFromUnicode)
  910. '                End If
  911. '                msToolTipBuffer = "safsaf"
  912.                 msToolTipBuffer = StrConv(UserControl.Extender.ToolTipText, vbFromUnicode)
  913. '                Debug.Print " > " & msToolTipBuffer & " : " & m_ToolTipText & " : " & UserControl.Extender.ToolTipText
  914.                 If Err.Number = 0 Then
  915.                     CopyMemory ttt, ByVal lParam, Len(ttt)
  916.                     ttt.lpszText = StrPtr(msToolTipBuffer)
  917.                     CopyMemory ByVal lParam, ttt, Len(ttt)
  918.                 End If
  919.             End If
  920.         Case WM_CANCELMODE
  921.             'A window has been put over this one
  922.             'flatten the button
  923. '            Flatten
  924.             mbGotFocus = False
  925.             mbLeftMouseDown = False
  926.             mbLeftWasDown = False
  927.             mbMouseDownFired = False
  928.     End Select
  929. WindowProc_Resume:
  930.     WindowProc = CallWindowProc(mWndProcNext, hwnd, uMsg, wParam, ByVal lParam)
  931.     Exit Function
  932. WindowProc_Error:
  933.     Resume WindowProc_Resume
  934. End Function
  935.